﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace JoeyLibs.IdleStartMenu.UIUtility
{
    public static class WPFControlExtentions
    {
        #region Column & Row
        public static UIElement SetColumn(this UIElement source, int column)
        {
            Grid.SetColumn(source, column);
            return source;
        }

        public static UIElement SetRow(this UIElement source, int row)
        {
            Grid.SetRow(source, row);
            return source;
        }

        public static int GetColumn(this UIElement source)
        {
            return Grid.GetColumn(source);
        }

        public static int GetRow(this UIElement source)
        {
            return Grid.GetRow(source);
        }

        public static int MoveColumn(this UIElement source, int offset)
        {
            int newIndex = source.GetColumn() + offset;
            source.SetColumn(newIndex);
            return newIndex;
        }

        public static int MoveRow(this UIElement source, int offset)
        {
            int newIndex = source.GetRow() + offset;
            source.SetRow(newIndex);
            return newIndex;
        }

        public static Grid AddColumn(this Grid source, double width, GridUnitType type = GridUnitType.Pixel)
        {
            ColumnDefinition cd = new ColumnDefinition();
            cd.Width = new GridLength(width, type);
            source.ColumnDefinitions.Add(cd);
            return source;
        }

        public static Grid AddRow(this Grid source, double height, GridUnitType type = GridUnitType.Pixel)
        {
            RowDefinition cd = new RowDefinition();
            cd.Height = new GridLength(height, type);
            source.RowDefinitions.Add(cd);
            return source;
        }
        #endregion
    }
}
